package com.jxt.mina.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class QueryMemeberIp {

	public String queryMemberIp(String memberId) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rset = null;
		String memberIp = "";
		String sql = "select member_ip from sys_member where member_id = ?";
		try {
			String userName = "root";
			String password = "111111";
			String url = "jdbc:mysql://localhost/test";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(url, userName, password);
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, memberId);
			rset = pstmt.executeQuery();
			while (rset.next()) {
				memberIp = rset.getString(1);
			}
		} catch (Exception e) {
			System.err.println(e);
		}finally{
			if(rset != null){
				try {
					rset.close();
				} catch (SQLException e) {
					System.err.println(e);
				}
			}
			if(pstmt != null){
				try {
					pstmt.close();
				} catch (SQLException e) {
					System.err.println(e);
				}
			}
			if(conn != null){
				try {
					conn.close();
				} catch (SQLException e) {
					System.err.println(e);
				}
			}
			
		}
		return memberIp;
	}
}
